<?php

namespace App\Http\Middleware;

use Closure;

use Nette\Mail\Message;
use Nette\Mail\SmtpMailer;

class EmailMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $rs = $next($request);
        if($request->user()){
        $mail = new Message;
        $mail->setFrom('laowang <15927598634@163.com>')
            ->addTo($request->user()->email)
            ->setSubject('隔壁老王的问候')
            ->setBody("我住隔壁我姓王");
        

        $mailer = new SmtpMailer([
        'host' => 'smtp.163.com',
        'username' => '15927598634',
        'password' => 'gj654321',
        
        ]);
        $mailer->send($mail);
        }

        return $rs;
    }
}